//
//  MXFindBlockTyprNineTableViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/14.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXFindBlockTyprNineTableViewCell.h"
#import "MXFindBlockTypeNineCollectionViewCell.h"
#import "MXNewViewItemDetailVC.h"
#import "MXFindWebViewVC.h"
#import "MXFindItemDetailWebViewVC.h"
@interface MXFindBlockTyprNineTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end
@implementation MXFindBlockTyprNineTableViewCell

- (void)dealloc
{
    [_naviNine release];
    [_model release];
    [_collectionView release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatCollectionView];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat WID = self.frame.size.width;
    
    CGFloat collectionViewX = 0;
    CGFloat collectionViewY = 0;
    CGFloat collectionViewW = WID;
    CGFloat collectionViewH = HEIGHTPRO * 500;
    self.collectionView.frame = CGRectMake(collectionViewX, collectionViewY, collectionViewW, collectionViewH);
}

#pragma mark - 创建集视图
- (void)creatCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    flowLayout.itemSize = CGSizeMake(WIDTHPRO * 160, HEIGHTPRO * 160);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(0 ,HEIGHTPRO * 20 , 0,HEIGHTPRO * 20);
    
    
    CGFloat contentWIDTH = self.frame.size.width;
    CGFloat contentHEIGHT = self.frame.size.height;
    
    self.collectionView = [[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, contentWIDTH, contentHEIGHT  - HEIGHTPRO * 49) collectionViewLayout:flowLayout] autorelease];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionView];
    
#warning 需自定义collectionViewcell
    [self.collectionView registerClass:[MXFindBlockTypeNineCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    }

#pragma mark - CollectionView 协议实现部分
/************************* CollectionView Delegate **************************/
//Collection中的组别个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//每个组别中元件的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}
//重用机制
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MXFindBlockTypeNineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor magentaColor];
    cell.layer.cornerRadius = 8;
    cell.layer.masksToBounds = YES;
    [cell getInfo:self.model rowNum:indexPath.row];
    return cell;
}


#pragma mark - 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
     MXFindItemDetailWebViewVC *ItemVC = [[[MXFindItemDetailWebViewVC alloc] init] autorelease];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dic in self.model.product) {
        [arr addObject:[dic objectForKey:@"url"]];
    }
    
    ItemVC.requestString = arr[indexPath.row];
    
    ItemVC.TitleString = @"商品详情";

    [self.naviNine pushViewController:ItemVC animated:YES];
}



-(void)setModel:(MXFindDetailModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
